<?php
include_once dirname(__FILE__)."/../../model/config.php";
		$_evaluateur=new evaluateur();
if(isset($_POST["operation"])){
if($_POST["operation"]=="INSERT"){
		if(isset($_POST["id"])){$_evaluateur->set_id($_POST["id"]);}
		if(isset($_POST["CIN"])){$_evaluateur->set_CIN($_POST["CIN"]);}
		if(isset($_POST["nom_enseig"])){$_evaluateur->set_nom_enseig($_POST["nom_enseig"]);}
		if(isset($_POST["prenom_enseig"])){$_evaluateur->set_prenom_enseig($_POST["prenom_enseig"]);}
		if(isset($_POST["tel_mobile"])){$_evaluateur->set_tel_mobile($_POST["tel_mobile"]);}
		if(isset($_POST["tel"])){$_evaluateur->set_tel($_POST["tel"]);}
		if(isset($_POST["fax"])){$_evaluateur->set_fax($_POST["fax"]);}
		if(isset($_POST["mail"])){$_evaluateur->set_mail($_POST["mail"]);}
		if(isset($_POST["grade"])){$_evaluateur->set_grade($_POST["grade"]);}
		if(isset($_POST["specialite"])){$_evaluateur->set_specialite($_POST["specialite"]);}
		if(isset($_POST["CODE_ETABLISSEMENT"])){$_evaluateur->set_CODE_ETABLISSEMENT($_POST["CODE_ETABLISSEMENT"]);}
		$res=$_evaluateur->INSERT(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}
elseif($_POST["operation"]=="DELETE"){
		if(isset($_POST["CIN"])){
		$_evaluateur->set_CIN($_POST["CIN"]);
		$res=$_evaluateur->DELETE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
		}
}
elseif($_POST["operation"]=="UPDATE"){
		if(isset($_POST["id"])){$_evaluateur->set_id($_POST["id"]);}
		if(isset($_POST["CIN"])){$_evaluateur->set_CIN($_POST["CIN"]);}
		if(isset($_POST["nom_enseig"])){$_evaluateur->set_nom_enseig($_POST["nom_enseig"]);}
		if(isset($_POST["prenom_enseig"])){$_evaluateur->set_prenom_enseig($_POST["prenom_enseig"]);}
		if(isset($_POST["tel_mobile"])){$_evaluateur->set_tel_mobile($_POST["tel_mobile"]);}
		if(isset($_POST["tel"])){$_evaluateur->set_tel($_POST["tel"]);}
		if(isset($_POST["fax"])){$_evaluateur->set_fax($_POST["fax"]);}
		if(isset($_POST["mail"])){$_evaluateur->set_mail($_POST["mail"]);}
		if(isset($_POST["grade"])){$_evaluateur->set_grade($_POST["grade"]);}
		if(isset($_POST["specialite"])){$_evaluateur->set_specialite($_POST["specialite"]);}
		if(isset($_POST["CODE_ETABLISSEMENT"])){$_evaluateur->set_CODE_ETABLISSEMENT($_POST["CODE_ETABLISSEMENT"]);}
		$res=$_evaluateur->UPDATE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}

}
else{
	$constraint='';$limit=0;$start=0;$pagination='';
	if(isset($_POST["id"]) && !empty($_POST["id"])){
		$constraint.=" AND id='".$_POST["id"]."'";
	}

	if(isset($_POST["CIN"]) && !empty($_POST["CIN"])){
		$constraint.=" AND CIN='".$_POST["CIN"]."'";
	}

	if(isset($_POST["nom_enseig"]) && !empty($_POST["nom_enseig"])){
		$constraint.=" AND nom_enseig='".$_POST["nom_enseig"]."'";
	}

	if(isset($_POST["prenom_enseig"]) && !empty($_POST["prenom_enseig"])){
		$constraint.=" AND prenom_enseig='".$_POST["prenom_enseig"]."'";
	}

	if(isset($_POST["tel_mobile"]) && !empty($_POST["tel_mobile"])){
		$constraint.=" AND tel_mobile='".$_POST["tel_mobile"]."'";
	}

	if(isset($_POST["tel"]) && !empty($_POST["tel"])){
		$constraint.=" AND tel='".$_POST["tel"]."'";
	}

	if(isset($_POST["fax"]) && !empty($_POST["fax"])){
		$constraint.=" AND fax='".$_POST["fax"]."'";
	}

	if(isset($_POST["mail"]) && !empty($_POST["mail"])){
		$constraint.=" AND mail='".$_POST["mail"]."'";
	}

	if(isset($_POST["grade"]) && !empty($_POST["grade"])){
		$constraint.=" AND grade='".$_POST["grade"]."'";
	}

	if(isset($_POST["specialite"]) && !empty($_POST["specialite"])){
		$constraint.=" AND specialite='".$_POST["specialite"]."'";
	}

	if(isset($_POST["CODE_ETABLISSEMENT"]) && !empty($_POST["CODE_ETABLISSEMENT"])){
		$constraint.=" AND CODE_ETABLISSEMENT='".$_POST["CODE_ETABLISSEMENT"]."'";
	}

	if(isset($_POST['limit'])){$limit=$_POST['limit'];}
	if(isset($_POST['start'])){$start=$_POST['start'];}
	if($limit>0){
		$pagination.=" LIMIT  $start,$limit"; 
}
		$res=$_evaluateur->SELECT($constraint,$pagination); 

		 $data=array();
		  while($row=$_evaluateur->fetch_object()){
		  	$data[]=$row;
	  	  }
  	 	 
		
	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('totalcount' => count($data),'result' => $data ));
	  	
	  }}
?>